// pages/fenxiangym/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    caifu: true,
    caifubang: [],
    sss:true,

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var param = {}
    param.buyerId = wx.getStorageSync('userId')
    param.sellerId = wx.getStorageSync('agent').id

    //请求 财富榜
    // 传参 sellerId 代理商id    buyerId 当前用户id
    app.HttpService.caifub(param).then(res => {
      console.log("财富榜", res)

      this.setData({
        caifubang: res.data.data.listRank,
        money: res.data.data.money,
        number: res.data.data.number
      })


    })

    // 
    // 

    //请求  我的邀请

    // 传参： buyerId 用户id; inviteId 当前邀请活动的id
    app.HttpService.caifub(param).then(res => {
      console.log("我的邀请", res)

    })


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    //请求有无邀请活动

    var that = this
    var params = {}
    params.sellerId = wx.getStorageSync('agent').id
    params.buyerId = wx.getStorageSync('userId')
    app.HttpService.youwuhud(params).then(res => {
      console.log("活动信息", res)

      that.setData({
        list: res.data.data.zxd,
        ford: res.data.data.friends,
        shu: res.data.data.isEffectNum,
        inviteId: res.data.data.inviteId,
        lists: res.data.data.list,
        inviteMoney: res.data.data.inviteMoney,
        rankNum: res.data.data.rankNum,
        share: res.data.data.share,
        codeUrl: res.data.data.codeUrl,
        imgUrl: res.data.data.imgUrl,
        buyerImgUrl: res.data.data.buyerImgUrl,


      })
    })








  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function(boj) {

    if (this.data.share == 1) {}
    var that = this

    let did = that.data.inviteId
    let uid = wx.getStorageSync('userId')
    var params = {}
    params.inviteId = that.data.inviteId
    params.BuyerId = wx.getStorageSync('userId')
    //点击分享触发
    app.HttpService.qqkiuk(params).then(res => {
      console.log("点击触发", res)
    })
    return {
      title: "扳子养车",
      path: 'pages/yqwa/index?uid=' + uid + "&did=" + did,
      imageUrl: "http://banzi-file.oss-cn-beijing.aliyuncs.com/email/20190908154937602TOP.png"
      //这里设定都是以"/page"开头,并拼接好传递的参数
    }
  },
  share: function() {

    console.log(222)

    var erwei = this.data.codeUrl
    var ditu = this.data.imgUrl
    var buyerImgUrl = this.data.buyerImgUrl

   

    wx.navigateTo({
      url: '/pages/fenxianghaibao/index?erwei=' + erwei + "&zhutu=" + ditu + "&touxiang=" + buyerImgUrl,
    })

  },
  // 切换选项卡我的邀请财富榜
  xuanzx: function() {

    var zhuangtai = this.data.caifu
    this.setData({
      caifu: !zhuangtai
    })

    var param = {}
    param.buyerId = wx.getStorageSync('userId')
    param.inviteId = this.data.inviteId

    // 传参： buyerId 用户id; inviteId 当前邀请活动的id
    app.HttpService.wdyqs(param).then(res => {
      console.log("我的邀请", res)
      this.setData({
        wodeyaoqing: res.data.data
      })
    })
  },
  tiaozhuan: function() {
    var s = this.data.inviteId
    wx.navigateTo({
      url: '/pages/yaoqingguize/index',
    })
  },
})